import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options  # 用于设置谷歌浏览器
from selenium.webdriver.chrome.service import Service  # 用于管理驱动
from selenium.webdriver.common.by import By


# 创建设置浏览器对象
def open_browser():
    o_llq = Options()
    o_llq.add_argument('--no-sandbox')
    o_llq.add_experimental_option('detach', True)
    llq = webdriver.Chrome(service=Service(r'D:\software\chromedriver-win64\chromedriver.exe'), options=o_llq)
    return llq


llq = open_browser()
llq.get('https://www.baidu.com')
llq.implicitly_wait(10)

# 页面前进和后退
# 浏览器左上角的两个箭头

# 输入哪吒2
llq.find_element(By.XPATH, '//*[@id="kw"]').send_keys("哪吒2")

time.sleep(2)
# 点击搜索
llq.find_element(By.XPATH, '//*[@id="su"]').click()

time.sleep(2)
# 返回到上一个页面(后退)
llq.back()

time.sleep(2)
# 网页前进
llq.forward()

